package com.edu.test;


import com.edu.bean.Employee;
import com.edu.bean.EmployeeExample;
import com.edu.mapper.EmployeeMapper;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.awt.print.Book;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class MyTest02 {

    SqlSession sqlSession = null;

    @Before
    public void init() throws IOException {
        String path = "mybatis-config.xml";//路径
        InputStream inputStream = Resources.getResourceAsStream(path);
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = sessionFactory.openSession();
    }


    @Test
    public void test01() {
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
        Employee employee = employeeMapper.selectByPrimaryKey(1);
        System.out.println(employee);
    }

    @Test
    public void test02() {
        EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
        //创建 查询模板
        EmployeeExample example = new EmployeeExample();
        //设置分页
        PageHelper.startPage(1,2);
        //查询模板 添加查询条件。
        example.or().andDepartIdEqualTo(3).andSalaryGreaterThan(new BigDecimal(5000));
        //查询结果去重
        example.setDistinct(true);
        //查询结果 排序
        example.setOrderByClause("salary DESC");
        for (Employee employee : employeeMapper.selectByExample(example)) {
            System.out.println(employee);
        }
    }
}
